$(document).ready(function(e){
    $(".ju-like").click(function(){
		/*likeAndShare(
			$(this).attr("data-title"),
			$(this).attr("data-item_id"),
			
			$(this).attr("data-pic_url"),
			"http://jie.wantujie.com/?id="+$(this).attr("data-id")+"&a=product" 
		);*/
		like2($(this).attr("data-item_id"));
	});
	$(".check").click(function(){
		check_in();	
	})
	//console.log($("#_tb_token_",parent.document).val());
	//$('#_tb_token_', parent.document).attr("type","text");
	//alert(window.parent.document.getElementById("_tb_token_").value);
});


function check_in(){
	var url = "/?m=api&a=check";
	$.ajax({
		dataType:"jsonp",
		url:url,
		jsonpCallback:"check_back",
		success: function(data){
		},
		error: function(){
			alert("error");
		}
	});
}

function check_back(data){
		if(data.code==1){
			showMsg("签到成功 ^_^ +1");
			$(".points").html(data.points);
		}else{
			showMsg("今天已经签过了，记得明天再来哦~~");
		}
		
}
function showMsg(msg){
	$("#mode_tips_v2").html("<span class=\"gtl_ico_succ\"></span>"+msg+"<span class=\"gtl_end\"></span>");
	$("#q_Msgbox").fadeIn();
	setTimeout(function(){
		$("#q_Msgbox").fadeOut(2000);
	},3500);
}
function likeAndShare(title,item_id,pic_url,url){
	console.log(escape(url));
	var now = new Date();
	var mSec = now.getTime();
	var url = "http://t.taobao.com/cooperate/publish_favor.do?_input_charset=utf-8&"+
		"t="+mSec+
		"&favor_type=3"+
		"&favor_target_key="+item_id+
		"&favor_sub_type="+
		"&favor_app_id=undefined"+
		"&comment=%E8%BF%99%E4%B8%AA%E5%AE%9D%E8%B4%9D%E6%88%91%E8%9B%AE%E5%96%9C%E6%AC%A2%E7%9A%84%E5%93%A6!~~%E5%A4%A7%E5%AE%B6%E6%9D%A5%E5%9B%B4%E8%A7%82%E4%B8%8B%EF%BC%81~"+
		"&pic="+encodeURI(pic_url)+
		"&client_id=170429"+
		"&type=webpage"+
		"&title="+encodeURI(title)+
		"&key="+escape(url)+
		"&_tb_token_=e9bbe5e1be6a7";
		$.ajax({
			dataType:"jsonp",
			url:url,
			jsonpCallback:"likeBack",
			success: function(data){
			},
			error: function(){
				alert("error");
			}
		});
}
function like2(id){
	var url = "/?m=api&a=like&item_id="+id;
	$.ajax({
		dataType:"jsonp",
		url:url,
		jsonpCallback:"like2Back",
		success: function(data){
		},
		error: function(){
			alert("error");
		}
	});
}
function like2Back(data){
	if(data.code!=0){
		//console.log(data.msg);
		showMsg("嗯嗯，喜欢了 ^_^ +1");
		$(".points").html(data.points);
	}
}
function likeBack(data){//发送feed的喜欢
	if(data.result.code==-1){
		showMsg("请您先登陆哦哦 ^_^ +1");
		window.location = "http://container.api.taobao.com/container?appkey=12587554";
	}else if(data.result.type=='success'){
		like2($(this).attr("data-id"));
	}else{
		showMsg("你已经喜欢过了哦哦 ^_^");
		console.log(data.result.type);
	}
}
